package com.itheima.test.newcustomer;

public class Cooker extends Thread{
    private Desk desk;
    public Cooker(Desk desk) {
        this.desk = desk;
    }

    @Override
    public void run() {
        while(true){
            synchronized (desk.getLock()){
                if(desk.getHamburgerNumber() == 0){
                    break;
                }else{
                    if(desk.isFlag()){//桌子上有汉堡
                        try {
                            desk.getLock().wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }else{//桌子上无汉堡
                        System.out.println("米其林高级汉堡扒厨师正在做汉堡");
                        desk.setFlag(true);//汉堡状态为有
                        desk.getLock().notifyAll();//叫醒吃货
                    }
                }
            }
        }
    }
}
